<template>
  <div>
    <zeda-dialog
      v-model="visible"
      width="1000px"
      title="抄表流水详情"
      :before-close="handleClose"
    >
      <desc-base-info
        :data="info"
        :colnum-info="colnumInfo"
        align="right"
        :no-line-height="true"
        label-width="120px"
        class="base-info"
      ></desc-base-info>
      <el-divider></el-divider>
      <desc-base-info
        :data="info"
        :colnum-info="contrastInfo"
        align="right"
        :no-line-height="true"
        label-width="120px"
        class="base-info"
      ></desc-base-info>
      <form-button
        slot="footer"
        cancel-text="关闭"
        :show-submit-button="false"
        @cancel="handleClose"
      ></form-button>
    </zeda-dialog>
  </div>
</template>
<script>
// import { detail } from "@/api/iot/stream";
import FormButton from "@/components/FormButton";
import { dealElectricity, deepClone } from "@/utils/index";
export default {
  components: {
    FormButton,
  },
  props: {
    visible: { type: Boolean, default: false },
    id: { type: [String, Number], default: "" },
    rowsData: { type: Object, default: {} },
  },
  data() {
    return {
      info: {},
      show: false,
    };
  },
  computed: {
    colnumInfo({ info }) {
      let arr = [];
      if (info.deviceModel == "3") {
        arr = [
          { label: "能耗终端", prop: "name", colNum: 2 },
          { label: "设备编号", prop: "deviceCode", colNum: 2 },
          { label: "物联网卡号", prop: "cardNum", colNum: 1 },
          { label: "电压", prop: "ua", colNum: 2 },
          { label: "电流", prop: "ia", colNum: 2 },
          { label: "有功功率", prop: "pa", colNum: 2 },
          { label: "无功功率", prop: "qa", colNum: 2 },
        ];
      } else {
        arr = [
          { label: "能耗终端", prop: "name", colNum: 2 },
          { label: "设备编号", prop: "deviceCode", colNum: 2 },
          { label: "物联网卡号", prop: "cardNum", colNum: 1 },
          { label: "A相电压", prop: "ua", colNum: 3 },
          { label: "B相电压", prop: "ub", colNum: 3 },
          { label: "C相电压", prop: "uc", colNum: 3 },
          { label: "A相电流", prop: "ia", colNum: 3 },
          { label: "B相电流", prop: "ib", colNum: 3 },
          { label: "C相电流", prop: "ic", colNum: 3 },
          { label: "AB相电压", prop: "uab", colNum: 3 },
          { label: "BC相电压", prop: "ubc", colNum: 3 },
          { label: "AC相电压", prop: "uac", colNum: 3 },
          { label: "A相有功功率", prop: "pa", colNum: 3 },
          { label: "B相有功功率", prop: "pb", colNum: 3 },
          { label: "C相有功功率", prop: "pc", colNum: 3 },
          { label: "A相无功功率", prop: "qa", colNum: 3 },
          { label: "B相无功功率", prop: "qb", colNum: 3 },
          { label: "C相无功功率", prop: "qc", colNum: 3 },
        ];
      }
      return arr;
    },
    contrastInfo({ info }) {
      return [
        { label: "电流变比CT", prop: "ct", colNum: 2 },
        { label: "电压变比PT", prop: "pt", colNum: 2 },
        { label: "尖峰用电量", prop: "spiksectionElectricity", colNum: 2 },
        { label: "高峰用电量", prop: "peaksectionElectricity", colNum: 2 },
        { label: "平段用电量", prop: "flatsectionElectricity", colNum: 2 },
        { label: "谷时用电量", prop: "valleysectionElectricity", colNum: 2 },
      ];
    },
  },
  watch: {
    visible(value) {
      if (value) {
        this.getInfo();
      } else {
        this.model = {
          substation: "",
          identity: "",
          taxNum: "",
          code: "",
          switchStatus: "",
        };
      }
    },
  },
  methods: {
    getInfo() {
      console.log(this.rowsData, "改行数据");
      this.info = this.rowsData;
      // 数据处理
      this.info.ua = dealElectricity(this.info.ua);
      this.info.ub = dealElectricity(this.info.ub);
      this.info.ia = dealElectricity(this.info.ia, 1000, 3);
      this.info.uc = dealElectricity(this.info.uc);
      this.info.ib = dealElectricity(this.info.ib, 1000, 3);
      this.info.ic = dealElectricity(this.info.ic, 1000, 3);
      this.info.uab = dealElectricity(this.info.uab);
      this.info.ubc = dealElectricity(this.info.ubc);
      this.info.uac = dealElectricity(this.info.uac);
      this.info.pa = dealElectricity(this.info.pa, 1000, 3);
      this.info.pb = dealElectricity(this.info.pb, 1000, 3);
      this.info.pc = dealElectricity(this.info.pc, 1000, 3);
      this.info.qa = dealElectricity(this.info.qa, 1000, 3);
      this.info.qb = dealElectricity(this.info.qb, 1000, 3);
      this.info.qc = dealElectricity(this.info.qc, 1000, 3);
      this.info.spiksectionElectricity = dealElectricity(
        this.info.spiksectionElectricity
      );
      this.info.peaksectionElectricity = dealElectricity(
        this.info.peaksectionElectricity
      );
      this.info.flatsectionElectricity = dealElectricity(
        this.info.flatsectionElectricity
      );
      this.info.valleysectionElectricity = dealElectricity(
        this.info.valleysectionElectricity
      );
      // detail({ id: this.id }).then((data) => {
      //   this.info = data;
      // });
    },
    handleClose(status) {
      this.$emit("close", typeof status === "boolean" ? status : false);
    },
  },
};
</script>
